<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 自己重新写快速排序
        var arr=[4,5,2,1,43,5,3,2,9]
function quicks(arr,left,right){
    // var len=arr.length,
    // partIndex,
    // letf = typeof left !== 'number' ? 0:left;
    // right =typeof right !== 'number' ? len-1:right;
    // if(left <right){
    //     partIndex=part(arr,left,right)
    //     quicks(arr,left,partIndex-1)
    //     quicks(arr,partIndex+1,right)
    // }
    var len=arr.length,
    partIndex,
    left =typeof left  !=='number' ? 0:left,
    right =typeof right !=='number' ? len-1:right;
    if(left <right){
        partIndex=part(arr,left,right)
        quicks(arr,left,partIndex-1)
        quicks(arr,partIndex+1,right)
    }
}
function part(arr,left,right){
    // var x=left;
    // var index=x+1;
    // for(var i=index;i<right;i++){
    //     if(arr[i]<arr[x]){
    //         swap(arr,i,index);
    //         index++;
    //     }
    // }
    // swap(arr,x,index-1)
    // return index-1;
    var x=left;
    var index=x+1;
    for(var i=index;i<right;i++){
        if(arr[i]<arr[x]){
            swap(arr,i,index)
            index++;
        }
    }
    swap(arr,x,index-1)
    return index-1;
}
    function swap(arr,i,j){
        var temp=arr[i];
        arr[i]=arr[j]
        arr[j]=temp;
    }
    console.log(quicks(arr))



    </script>
</body>
</html>